﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HRC.Library.ContextFoundation;
using Lehnet.BusinessLayer;
using Lehnet.BusinessLayer.Interfaces;
using Lehnet.Models;
using Lehnet.WebUI.CustomAttributes;

namespace Lehnet.WebUI.Controllers
{
    [PersonelAuthorize]
    public class MusteriController : Controller
    {
        //
        // GET: /Musteri/

        public ActionResult Index()
        {
            return View();
        }

        public JsonResult GetAllMusterilerAjax()
        {
            var mb = ProxyHelper<MusteriBusiness, IMusteriBusiness>.Instance.AddOrGet();
            JsonResult result = Json(mb.LoadAll());
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return result;
        }

        public PartialViewResult Create(int? Id)
        {
            var m = new Musteri();
            if (Id != null)
            {
                var mb = ProxyHelper<MusteriBusiness, IMusteriBusiness>.Instance.AddOrGet();
                m = mb.LoadMusteriById((int)Id);
            }
            return PartialView(m);
        }
        [HttpPost]
        public PartialViewResult Create(Models.Musteri musteri)
        {
            var ib = ProxyHelper<MusteriBusiness, IMusteriBusiness>.Instance.AddOrGet();
            try
            {
                ib.SaveOrUpdate(musteri);
                ViewBag.ResultMessage = "İlçe Başarılı Bir Şekilde Oluşturuldu";
                //ControllerContext.HttpContext.Response.Redirect("Login");
            }
            catch (Exception exp)
            {
                ViewBag.ResultMessage = "İlçe oluşturulurken hata oluştu:" + exp.Message;
            }
            return PartialView();
        }

        public JsonResult DeleteMusteriAjax(int musteriId)
        {
            var mb = ProxyHelper<MusteriBusiness, IMusteriBusiness>.Instance.AddOrGet();
            mb.Delete(musteriId);
            JsonResult result = Json("Oldu, çok da güzel oldu!");
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return result;
        }
    }
}
